#include "flash_api.h"
#include "device_parameter.h"

static DeviceInformation_t DeviceInformation = {0};

// tag: IO板设备信息表
static IoboardDeviceInfo_t IoboardDeviceInfoTable[IOBOARD_DEVICE_NUM] = {0}; // IO板设备信息表

IoboardDeviceInfo_t *GetIoBoardDeviceInfoTablePtr(void)
{
  return &IoboardDeviceInfoTable[0];
}

uint8_t GetDeviceInitStatus(void)
{
  return DeviceInformation.DeviceInitState;
}

void SetDeviceInitStatus(uint8_t Status)
{
  DeviceInformation.DeviceInitState = Status;
}

bool GetTheKeyToResetEn(void)
{
  return DeviceInformation.SensorFunctionControl.SensorControlBit.KeyTiggerResetEn;
}

void SetTheKeyToResetEn(bool En)
{
  DeviceInformation.SensorFunctionControl.SensorControlBit.KeyTiggerResetEn = En;
}

bool GetStartTimeVerifyEn(void)
{
  return DeviceInformation.SensorFunctionControl.SensorControlBit.StartTimeVerifyEn;
}

void SetStartTimeVerifyEn(bool En)
{
  DeviceInformation.SensorFunctionControl.SensorControlBit.StartTimeVerifyEn = En;
}

bool GetAllowedToOpenDoubleLockEn(void)
{
  return DeviceInformation.SensorFunctionControl.SensorControlBit.DoubleLockEn;
}

void SetAllowedToOpenDoubleLockEn(bool En)
{
  DeviceInformation.SensorFunctionControl.SensorControlBit.DoubleLockEn = En;
}

bool GetNormalOpenEn(void)
{
  return DeviceInformation.SensorFunctionControl.SensorControlBit.NormalOpenEn;
}

void SetNormalOpenEn(bool En)
{
  DeviceInformation.SensorFunctionControl.SensorControlBit.NormalOpenEn = En;
}

uint8_t GetOnboardFunctionsInBatches(void)
{
  return DeviceInformation.SensorFunctionControl.SensorFunctionControl;
}

bool SetOnboardFunctionsInBatches(uint8_t BasicContorl)
{
  DeviceInformation.SensorFunctionControl.SensorFunctionControl = BasicContorl;
  return true;
}

uint8_t GetObtainTheDeviceModel(void)
{
  return DeviceInformation.VersionControl.DeviceModel;
}

bool SetObtainTheDeviceModel(DeviceType_t DeviceModel)
{
  bool OperationStatus = false;

  switch (DeviceModel)
  {
  case B_C:
  case B_CM:
  case BT_C:
  case BT_CM:
  case B4_CM:
  case TYB_C:
  case HYB_C:
  case BT_CMA:
  case BT_CMF:
  case B4_CMF:
  case B4_CMA:
  case TW_BC4_01:
  case EC01_CR_B_C:
  case PS01_BR_C:
  case DA01_B_C:
  case CR01_BU:
  case TYPE_NO_DEFINE:
  {
    OperationStatus = true;
    DeviceInformation.VersionControl.DeviceModel = DeviceModel;
  }
  break;
  }

  return OperationStatus;
}

bool GetQualityInspectorCode(void *pCode)
{
  if (pCode != NULL)
  {
    memcpy(pCode, DeviceInformation.VersionControl.QCCode, NUMBER_OF_QC_CODE);
    return true;
  }

  return false;
}

bool SetQualityInspectorCode(const void *pCode)
{
  if (pCode != NULL)
  {
    const char *pQCCode = (const char *)pCode;

    if (strlen(pQCCode) <= NUMBER_OF_QC_CODE)
    {
      memset(DeviceInformation.VersionControl.QCCode, 0, NUMBER_OF_QC_CODE);
      strcpy(DeviceInformation.VersionControl.QCCode, pQCCode);

      return true;
    }
  }

  return false;
}

bool ObtainCircuitBoardModel(void *pModel)
{
  if (pModel != NULL)
  {
    memcpy(pModel, DeviceInformation.VersionControl.PcbVersionNumber, NUMBER_OF_FIRMWARE_VERSION);
    return true;
  }

  return false;
}

bool WriteCircuitBoardType(const void *pModel)
{
  if (pModel != NULL)
  {
    const char *pPcbVersionNumber = (const char *)pModel;

    if (strlen(pPcbVersionNumber) <= NUMBER_OF_FIRMWARE_VERSION)
    {
      memset(DeviceInformation.VersionControl.PcbVersionNumber, 0, NUMBER_OF_FIRMWARE_VERSION);
      strcpy(DeviceInformation.VersionControl.PcbVersionNumber, pPcbVersionNumber);

      return true;
    }
  }

  return false;
}

uint32_t ObtainTheDeliveryDateOfTheDevice(void)
{
  return DeviceInformation.VersionControl.DateOfProduction;
}

bool SetTheDeviceDeliveryDate(uint32_t DateOfProduction)
{
  if ((DateOfProduction != 0x00000000) && (DateOfProduction != 0xFFFFFFFF))
  {
    DeviceInformation.VersionControl.DateOfProduction = DateOfProduction;
    return true;
  }

  return false;
}

bool GetDeviceFirmwareVersion(void *pVersion)
{
  if (pVersion != NULL)
  {
    memcpy(pVersion, DeviceInformation.VersionControl.FirmwareVersionNumber, NUMBER_OF_FIRMWARE_VERSION);
    return true;
  }

  return false;
}

bool SetDeviceFirmwareVersion(void *pVersion)
{
  if (pVersion != NULL)
  {
    const char *pFirmwareVersionNumber = (const char *)pVersion;

    if (strlen(pFirmwareVersionNumber) <= NUMBER_OF_FIRMWARE_VERSION)
    {
      memset(DeviceInformation.VersionControl.FirmwareVersionNumber, 0, NUMBER_OF_FIRMWARE_VERSION);
      strcpy(DeviceInformation.VersionControl.FirmwareVersionNumber, pFirmwareVersionNumber);

      return true;
    }
  }

  return false;
}

bool GetChipModel(void *pChipModel)
{
  if (pChipModel != NULL)
  {
    memcpy(pChipModel, DeviceInformation.VersionControl.ChipModel, NUMBER_OF_CHIP_TYPE_LENGTH);
    return true;
  }

  return false;
}

bool SettingTheChipModel(const char *pChipModel)
{
  if (pChipModel != NULL)
  {
    const char *pDeiceChipModel = (const char *)pChipModel;

    if (strlen(pDeiceChipModel) <= NUMBER_OF_CHIP_TYPE_LENGTH)
    {
      memset(DeviceInformation.VersionControl.ChipModel, 0, NUMBER_OF_CHIP_TYPE_LENGTH);
      strcpy(DeviceInformation.VersionControl.ChipModel, pDeiceChipModel);

      return true;
    }
  }

  return false;
}

uint8_t GetSystemTimeZone(void)
{
  uint8_t TimeZone = DeviceInformation.DeviceAttribute.TimeZone;

  if (((TimeZone >= 0) && (TimeZone <= 14)) || ((TimeZone >= 0xF5) && (TimeZone <= 0xFF)))
    return TimeZone;

  return DEFAULT_TIME_ZONE_OFFSET;
}

bool SetSystemTimeZone(uint8_t TimeZone)
{
  if (((TimeZone >= 0) && (TimeZone <= 14)) || ((TimeZone >= 0xF5) && (TimeZone <= 0xFF)))
  {
    DeviceInformation.DeviceAttribute.TimeZone = TimeZone;
    return true;
  }

  return false;
}

uint16_t GetGuestCardReplaceId(void)
{
  return DeviceInformation.ReplaceInformation.GusetCardReplaceId;
}

bool SetGuestCardReplaceId(uint16_t ReplaceId)
{
  DeviceInformation.ReplaceInformation.GusetCardReplaceId = ReplaceId;
  return true;
}

uint16_t GetMasterCardReplaceId(void)
{
  return DeviceInformation.ReplaceInformation.MasterCardReplaceId;
}

bool SetMasterCardReplaceId(uint16_t ReplaceId)
{
  DeviceInformation.ReplaceInformation.MasterCardReplaceId = ReplaceId;
  return true;
}

uint16_t GetBuildCardReplaceId(void)
{
  return DeviceInformation.ReplaceInformation.BuildCardReplaceId;
}

bool SetBuildCardReplaceId(uint16_t ReplaceId)
{
  DeviceInformation.ReplaceInformation.BuildCardReplaceId = ReplaceId;
  return true;
}

uint16_t GetFloorCardReplaceId(void)
{
  return DeviceInformation.ReplaceInformation.FloorCardReplaceId;
}

bool SetFloorCardReplaceId(uint16_t ReplaceId)
{
  DeviceInformation.ReplaceInformation.FloorCardReplaceId = ReplaceId;
  return true;
}

uint16_t GetParkCardReplaceId(void)
{
  return DeviceInformation.ReplaceInformation.ParkCardReplaceId;
}

bool SetParkCardReplaceId(uint16_t ReplaceId)
{
  DeviceInformation.ReplaceInformation.ParkCardReplaceId = ReplaceId;
  return true;
}

uint16_t GetNormalOpenCardReplaceId(void)
{
  return DeviceInformation.ReplaceInformation.NormalOpenCardReplaceId;
}

bool SetNormalOpenCardReplaceId(uint16_t ReplaceId)
{
  DeviceInformation.ReplaceInformation.NormalOpenCardReplaceId = ReplaceId;
  return true;
}

uint32_t GetGuestCardReplaceTime(void)
{
  return DeviceInformation.ReplaceInformation.GusetCardReplaceTime;
}

bool SetGuestCardReplaceTime(uint32_t ReplaceTime)
{
  DeviceInformation.ReplaceInformation.GusetCardReplaceTime = ReplaceTime;
  return true;
}

uint32_t GetMasterCardReplaceTime(void)
{
  return DeviceInformation.ReplaceInformation.MasterCardReplaceTime;
}

bool SetMasterCardReplaceTime(uint32_t ReplaceTime)
{
  DeviceInformation.ReplaceInformation.MasterCardReplaceTime = ReplaceTime;
  return true;
}

uint32_t GetBuildCardReplaceTime(void)
{
  return DeviceInformation.ReplaceInformation.BuildCardReplaceTime;
}

bool SetBuildCardReplaceTime(uint32_t ReplaceTime)
{
  DeviceInformation.ReplaceInformation.BuildCardReplaceTime = ReplaceTime;
  return true;
}

uint32_t GetFloorCardReplaceTime(void)
{
  return DeviceInformation.ReplaceInformation.FloorCardReplaceTime;
}

bool SetFloorCardReplaceTime(uint32_t ReplaceTime)
{
  DeviceInformation.ReplaceInformation.FloorCardReplaceTime = ReplaceTime;
  return true;
}

uint32_t GetParkCardReplaceTime(void)
{
  return DeviceInformation.ReplaceInformation.ParkCardReplaceTime;
}

bool SetParkCardReplaceTime(uint32_t ReplaceTime)
{
  DeviceInformation.ReplaceInformation.ParkCardReplaceTime = ReplaceTime;
  return true;
}

uint32_t GetNormalOpenCardReplaceTime(void)
{
  return DeviceInformation.ReplaceInformation.NormalOpenCardReplaceTime;
}

bool SetNormalOpenCardReplaceTime(uint32_t ReplaceTime)
{
  DeviceInformation.ReplaceInformation.NormalOpenCardReplaceTime = ReplaceTime;
  return true;
}

uint8_t GetSystemVolumeLevel(void)
{
  uint8_t VolumeLevel = DeviceInformation.DeviceAttribute.SystemVolume;

  if ((VolumeLevel >= MIX_VOLUME_LEVEL) && (VolumeLevel <= MAX_VOLUME_LEVEL))
    return VolumeLevel;

  return DEFAULT_VOLUME_LEVEL;
}

bool SetSystemVolumeLevel(uint8_t VolumeLevel)
{
  if ((VolumeLevel >= MIX_VOLUME_LEVEL) && (VolumeLevel <= MAX_VOLUME_LEVEL))
  {
    DeviceInformation.DeviceAttribute.SystemVolume = VolumeLevel;
    return true;
  }

  return false;
}

uint8_t GetMotorDriveTime(void)
{
  if ((DeviceInformation.DeviceAttribute.MotorDriveTime >= MIX_MOTOR_DRIVE_TIME) && (DeviceInformation.DeviceAttribute.MotorDriveTime <= MAX_MOTOR_DRIVE_TIME))
    return DeviceInformation.DeviceAttribute.MotorDriveTime;

  return DEFAULT_MOTOR_DRIVE_TIME;
}

bool SetMotorDriveTime(uint8_t DriveTime)
{
  if ((DriveTime >= MIX_MOTOR_DRIVE_TIME) && (DriveTime < MAX_MOTOR_DRIVE_TIME))
  {
    DeviceInformation.DeviceAttribute.MotorDriveTime = DriveTime;
    return true;
  }

  return false;
}

uint8_t GetUnlockTime(void)
{
  uint8_t TimeOfUnlock = DeviceInformation.DeviceAttribute.UnlockingTime;

  if ((TimeOfUnlock >= MIX_UNLOCK_TIME) && (TimeOfUnlock <= MAX_UNLOCK_TIME))
    return TimeOfUnlock;

  return DEFAULT_UNLOCKING_TIME;
}

bool SetUnlockTime(uint8_t TimeOfUnlock)
{
  if ((TimeOfUnlock >= MIX_UNLOCK_TIME) && (TimeOfUnlock <= MAX_UNLOCK_TIME))
  {
    DeviceInformation.DeviceAttribute.UnlockingTime = TimeOfUnlock;
    return true;
  }

  return false;
}

uint8_t GetNetworkOperator(void)
{
  uint8_t Operator = DeviceInformation.DeviceAttribute.NetworkOperator;

  switch (Operator)
  {
  case CHINA_MOBILE:
  case CHINA_UNICOM:
  case CHINA_TELECOM:
    return Operator;
  }

  return CHINA_MOBILE;
}

bool SetNetworkOperator(uint8_t Operator)
{
  bool OperationStatus = false;

  switch (Operator)
  {
  case CHINA_MOBILE:
  case CHINA_UNICOM:
  case CHINA_TELECOM:
  {
    OperationStatus = true;
    DeviceInformation.DeviceAttribute.NetworkOperator = Operator;
  }
  break;
  }

  return OperationStatus;
}

uint16_t GetHeartbeatTransmissionCycle(void)
{
  uint16_t HeartbeatCyclel = DeviceInformation.DeviceAttribute.HeartbeatCyclel;
  if ((HeartbeatCyclel >= MIX_HEARTBEAT_CYCLE) && (HeartbeatCyclel <= MAX_HEARTBEAT_CYCLE))
    return HeartbeatCyclel;

  return DEFAULT_HEARTBEAT_CYCLE;
}

bool SetHeartbeatTransmissionCycle(uint16_t HeartbeatCyclel)
{
  if ((HeartbeatCyclel >= MIX_HEARTBEAT_CYCLE) && (HeartbeatCyclel <= MAX_HEARTBEAT_CYCLE))
  {
    DeviceInformation.DeviceAttribute.HeartbeatCyclel = HeartbeatCyclel;
    return true;
  }

  return false;
}

uint8_t GetNumberOfCardholder(void)
{
  uint8_t Quantity = DeviceInformation.DeviceAttribute.NumberOfCardholder;

  if ((Quantity >= MIX_NUMBER_OF_CARDHOLDER) && (Quantity <= MAX_NUMBER_OF_CARDHOLDER))
    return Quantity;

  return DEFAULT_NUMBER_OF_CARDHOLDER;
}

bool SetNumberOfCardholder(uint8_t Quantity)
{
  if ((Quantity >= MIX_NUMBER_OF_CARDHOLDER) && (Quantity <= MAX_NUMBER_OF_CARDHOLDER))
  {
    DeviceInformation.DeviceAttribute.NumberOfCardholder = Quantity;
    return true;
  }

  return false;
}

uint8_t GetAllowableTimeError(void)
{
  uint8_t TimeError = DeviceInformation.DeviceAttribute.AllowableTimeError;

  if ((TimeError >= MIX_ALLOWABLE_TIME_ERROR) && (TimeError <= MAX_ALLOWABLE_TIME_ERROR))
    return TimeError;

  return DEFAULT_ALLOWABLE_TIME_ERROR;
}

bool SetAllowableTimeError(uint8_t TimeError)
{
  if ((TimeError >= MIX_ALLOWABLE_TIME_ERROR) && (TimeError <= MAX_ALLOWABLE_TIME_ERROR))
  {
    DeviceInformation.DeviceAttribute.AllowableTimeError = TimeError;
    return true;
  }

  return false;
}

uint8_t GetKeyboardSensitivity(void)
{
  uint8_t Sensitivity = DeviceInformation.DeviceAttribute.KeyBoardSensitivity;

  if ((Sensitivity >= MIX_KEYBOARD_SENSITIVITY) && (Sensitivity <= MAX_KEYBOARD_SENSITIVITY))
    return Sensitivity;

  return DEFAULT_KEYBOARD_SENSITIVITY;
}

bool SetKeyboardSensitivity(uint8_t Sensitivity)
{
  if ((Sensitivity >= MIX_KEYBOARD_SENSITIVITY) && (Sensitivity <= MAX_KEYBOARD_SENSITIVITY))
  {
    DeviceInformation.DeviceAttribute.KeyBoardSensitivity = Sensitivity;
    return true;
  }

  return false;
}

uint8_t GetOfflineCardFunctionEnable(void)
{
  return DeviceInformation.DeviceAttribute.OfflineCardEn.Ident;
}

bool SetOfflineCardFunctionEnable(uint8_t EnableBit)
{
  DeviceInformation.DeviceAttribute.OfflineCardEn.Ident = EnableBit;
  return true;
}

uint8_t GetProtocolFormat(void)
{
  uint8_t ProtocolFormat = DeviceInformation.DeviceAttribute.ProtocolFormat;

  switch (ProtocolFormat)
  {
  case PROTOCOL_FORMAT_DL:
  case PROTOCOL_FORMAT_YGS:
  case PROTOCOL_FORMAT_SMSZ:
    return ProtocolFormat;
  }

  return PROTOCOL_FORMAT_YGS;
}

bool SetProtocolFormat(uint8_t ProtocolFormat)
{
  bool OperationMode = false;

  switch (ProtocolFormat)
  {
  case PROTOCOL_FORMAT_DL:
  case PROTOCOL_FORMAT_YGS:
  case PROTOCOL_FORMAT_SMSZ:
  {
    OperationMode = true;
    DeviceInformation.DeviceAttribute.ProtocolFormat = ProtocolFormat;
  }
  break;
  }

  return OperationMode;
}

uint8_t GetSearchTimeout(void)
{
  uint8_t SearchTime = DeviceInformation.DeviceAttribute.SearchTimeout;

  if ((SearchTime >= MIX_FACE_SEARCH_TIME) && (SearchTime <= MAX_FACE_SEARCH_TIME))
    return SearchTime;

  return DEFAULT_FACE_SEARCH_TIME;
}

bool SetSearchTimeout(uint8_t SearchTime)
{
  if ((SearchTime >= MIX_FACE_SEARCH_TIME) && (SearchTime <= MAX_FACE_SEARCH_TIME))
  {
    DeviceInformation.DeviceAttribute.SearchTimeout = SearchTime;
    return true;
  }

  return false;
}

bool GetGuestCardEn(void)
{
  if (DeviceInformation.DeviceAttribute.OfflineCardEn.OfflineCardEnBit.Function == DISABLE_SPECIFIC_CARD_TYPE)
  {
    if (DeviceInformation.DeviceAttribute.OfflineCardEn.OfflineCardEnBit.GuestCard == false)
      return true;
  }
  else
  {
    if (DeviceInformation.DeviceAttribute.OfflineCardEn.OfflineCardEnBit.GuestCard == true)
      return true;
  }

  return false;
}

bool GetMasterCardEn(void)
{
  if (DeviceInformation.DeviceAttribute.OfflineCardEn.OfflineCardEnBit.Function == DISABLE_SPECIFIC_CARD_TYPE)
  {
    if (DeviceInformation.DeviceAttribute.OfflineCardEn.OfflineCardEnBit.MasterCard == false)
      return true;
  }
  else
  {
    if (DeviceInformation.DeviceAttribute.OfflineCardEn.OfflineCardEnBit.MasterCard == true)
      return true;
  }

  return false;
}

bool GetBuildCardEn(void)
{
  if (DeviceInformation.DeviceAttribute.OfflineCardEn.OfflineCardEnBit.Function == DISABLE_SPECIFIC_CARD_TYPE)
  {
    if (DeviceInformation.DeviceAttribute.OfflineCardEn.OfflineCardEnBit.BuildCard == false)
      return true;
  }
  else
  {
    if (DeviceInformation.DeviceAttribute.OfflineCardEn.OfflineCardEnBit.BuildCard == true)
      return true;
  }

  return false;
}

bool GetFloorCardEn(void)
{
  if (DeviceInformation.DeviceAttribute.OfflineCardEn.OfflineCardEnBit.Function == DISABLE_SPECIFIC_CARD_TYPE)
  {
    if (DeviceInformation.DeviceAttribute.OfflineCardEn.OfflineCardEnBit.FloorCard == false)
      return true;
  }
  else
  {
    if (DeviceInformation.DeviceAttribute.OfflineCardEn.OfflineCardEnBit.FloorCard == true)
      return true;
  }

  return false;
}

bool GetParkCardEn(void)
{
  if (DeviceInformation.DeviceAttribute.OfflineCardEn.OfflineCardEnBit.Function == DISABLE_SPECIFIC_CARD_TYPE)
  {
    if (DeviceInformation.DeviceAttribute.OfflineCardEn.OfflineCardEnBit.ParkCard == false)
      return true;
  }
  else
  {
    if (DeviceInformation.DeviceAttribute.OfflineCardEn.OfflineCardEnBit.ParkCard == true)
      return true;
  }

  return false;
}

bool GetNormalOpenCardEn(void)
{
  if (DeviceInformation.DeviceAttribute.OfflineCardEn.OfflineCardEnBit.Function == DISABLE_SPECIFIC_CARD_TYPE)
  {
    if (DeviceInformation.DeviceAttribute.OfflineCardEn.OfflineCardEnBit.NormalOpenCard == false)
      return true;
  }
  else
  {
    if (DeviceInformation.DeviceAttribute.OfflineCardEn.OfflineCardEnBit.NormalOpenCard == true)
      return true;
  }

  return false;
}

uint8_t GetBluetoothConnectionTimeout(void)
{
  uint8_t Timeout = DeviceInformation.DeviceAttribute.BluetoothConnectionTimeout;

  if ((Timeout >= MIX_CONNECTION_TIMEOUT) && (Timeout <= MAX_CONNECTION_TIMEOUT))
    return Timeout;

  return DEFAULT_CONNECTION_TIMEOUT;
}

bool SetBluetoothConnectionTimeout(uint8_t Timeout)
{
  if ((Timeout >= MIX_CONNECTION_TIMEOUT) && (Timeout <= MAX_CONNECTION_TIMEOUT))
  {
    DeviceInformation.DeviceAttribute.BluetoothConnectionTimeout = Timeout;
    return true;
  }

  return false;
}

uint8_t GetBluetoothUpdateRaidioInterval(void)
{
  uint8_t Interval = DeviceInformation.DeviceAttribute.BluetoothUpdateRaidioInterval;

  if ((Interval >= MIX_UPDATE_BLUETOOTH_BROADCAST_INTERVAL) && (Interval <= MAX_UPDATE_BLUETOOTH_BROADCAST_INTERVAL))
    return Interval;

  return DEFAULT_UPDATE_BLUETOOTH_BROADCAST_INTERVAL;
}

bool SetBluetoothUpdateRaidioInterval(uint8_t Interval)
{
  if ((Interval >= MIX_UPDATE_BLUETOOTH_BROADCAST_INTERVAL) && (Interval <= MAX_UPDATE_BLUETOOTH_BROADCAST_INTERVAL))
  {
    DeviceInformation.DeviceAttribute.BluetoothUpdateRaidioInterval = Interval;
    return true;
  }

  return false;
}

uint32_t GetDeviceLastActionTime(void)
{
  return DeviceInformation.DeviceAttribute.LastActiveTimestamp;
}

void SetDeviceLastActionTime(uint32_t Time)
{
  DeviceInformation.DeviceAttribute.LastActiveTimestamp = Time;
}

uint8_t GetErrorPromptFunctionConfiguration(void)
{
  return DeviceInformation.DeviceAttribute.ErrorPromptFunctionControl.Ident;
}

bool SetErrorPromptFunctionConfiguration(uint8_t Configuration)
{
  uint8_t LockedInTime = Configuration & 0x3F;
  if ((LockedInTime >= MIX_SYSTEM_LOCKED_TIME) && (LockedInTime <= MAX_SYSTEM_LOCKED_TIME))
  {
    DeviceInformation.DeviceAttribute.ErrorPromptFunctionControl.Ident = Configuration;
    return true;
  }

  return false;
}

bool GetRfidErrorPromptFunctionEnable(void)
{
  return DeviceInformation.DeviceAttribute.ErrorPromptFunctionControl.ErrorPromptFunctionControlBit.Rfid;
}

void SetRfidErrorPromptFunctionEn(bool En)
{
  DeviceInformation.DeviceAttribute.ErrorPromptFunctionControl.ErrorPromptFunctionControlBit.Rfid = En;
}

bool GetSafetyModuleErrorPromptFunctionEnable(void)
{
  return DeviceInformation.DeviceAttribute.ErrorPromptFunctionControl.ErrorPromptFunctionControlBit.SafetyModule;
}

void SetSafetyModuleErrorPromptFunctionEn(bool En)
{
  DeviceInformation.DeviceAttribute.ErrorPromptFunctionControl.ErrorPromptFunctionControlBit.SafetyModule = En;
}

uint8_t GetSystemLockedTime(void)
{
  uint8_t LockedInTime = DeviceInformation.DeviceAttribute.ErrorPromptFunctionControl.ErrorPromptFunctionControlBit.LockedTime;
  if ((LockedInTime >= MIX_SYSTEM_LOCKED_TIME) && (LockedInTime <= MAX_SYSTEM_LOCKED_TIME))
    return LockedInTime;

  return DEFAULT_SYSTEM_LOCKED_TIME;
}

bool SetSystemLockedTime(uint8_t LockedInTime)
{
  if ((LockedInTime >= MIX_SYSTEM_LOCKED_TIME) && (LockedInTime <= MAX_SYSTEM_LOCKED_TIME))
  {
    DeviceInformation.DeviceAttribute.ErrorPromptFunctionControl.ErrorPromptFunctionControlBit.LockedTime = LockedInTime;
    return true;
  }

  return false;
}

uint8_t GetCardReadingSensitivity(void)
{
  uint8_t Sensitivity = DeviceInformation.DeviceAttribute.CardReadingSensitivity;

  if ((Sensitivity >= MIX_CARD_RECOGNITION_SENSITIVITY) && (Sensitivity <= MAX_CARD_RECOGNITION_SENSITIVITY))
    return Sensitivity;

  return DEFAULT_CARD_RECOGNITION_SENSITIVITY;
}

bool SetCardReadingSensitivity(uint8_t Sensitivity)
{
  if ((Sensitivity >= MIX_CARD_RECOGNITION_SENSITIVITY) && (Sensitivity <= MAX_CARD_RECOGNITION_SENSITIVITY))
  {
    DeviceInformation.DeviceAttribute.CardReadingSensitivity = Sensitivity;
    return true;
  }

  return false;
}

uint8_t GetFalseLockDetcetionInterval(void)
{
  uint8_t Interval = DeviceInformation.DeviceAttribute.FlaseLockBlinkingInterval;

  if (((Interval >= MIX_FLASE_LOCK_DETCETION_INTERVAL_TIME) && (Interval <= MAX_FLASE_LOCK_DETCETION_INTERVAL_TIME)) || (Interval == 0))
    return Interval;

  return DEFAULT_FLASE_LOCK_DETCETION_INTERVAL_TIME;
}

bool SetFalseLockDetcetionInterval(uint8_t Interval)
{
  if (((Interval >= MIX_FLASE_LOCK_DETCETION_INTERVAL_TIME) && (Interval <= MAX_FLASE_LOCK_DETCETION_INTERVAL_TIME)) || (Interval == 0))
  {
    DeviceInformation.DeviceAttribute.FlaseLockBlinkingInterval = Interval;
    return true;
  }

  return false;
}

uint8_t GetTheBreakInDetcetionInterval(void)
{
  uint8_t Interval = DeviceInformation.DeviceAttribute.BreakInBlinkingInterval;

  if (((Interval >= MIX_BREAK_IN_DETCETION_INTERVAL_TIME) && (Interval <= MAX_BREAK_IN_DETCETION_INTERVAL_TIME)) || (Interval == 0))
    return Interval;

  return DEFAULT_BREAK_IN_DETCETION_INTERVAL_TIME;
}

bool SetBreakInDetcetionInterval(uint8_t Interval)
{
  if (((Interval >= MIX_BREAK_IN_DETCETION_INTERVAL_TIME) && (Interval <= MAX_BREAK_IN_DETCETION_INTERVAL_TIME)) || (Interval == 0))
  {
    DeviceInformation.DeviceAttribute.BreakInBlinkingInterval = Interval;
    return true;
  }

  return false;
}

uint8_t GetNormalOpenReminderInterval(void)
{
  uint8_t Interval = DeviceInformation.DeviceAttribute.NormalOpenBlinkingInterval;

  if (((Interval >= MIX_NORMAL_OPEN_HINT_INTERVAL_TIME) && (Interval <= MAX_NORMAL_OPEN_HINT_INTERVAL_TIME)) || (Interval == 0))
    return Interval;

  return DEFAULT_NORMAL_OPEN_HINT_INTERVAL_TIME;
}

bool SetNormalOpenReminderInterval(uint8_t Interval)
{
  if (((Interval >= MIX_NORMAL_OPEN_HINT_INTERVAL_TIME) && (Interval <= MAX_NORMAL_OPEN_HINT_INTERVAL_TIME)) || (Interval == 0))
  {
    DeviceInformation.DeviceAttribute.NormalOpenBlinkingInterval = Interval;
    return true;
  }

  return false;
}

uint8_t GetLockedInReminderInterval(void)
{
  uint8_t Interval = DeviceInformation.DeviceAttribute.LockedInBlinkingInterval;

  if (((Interval >= MIX_LOCKED_IN_HINT_INTERVAL_TIME) && (Interval <= MAX_LOCKED_IN_HINT_INTERVAL_TIME)) || (Interval == 0))
    return Interval;

  return DEFAULT_LOCKED_IN_HINT_INTERVAL_TIME;
}

bool SetLockedInReminderInterval(uint8_t Interval)
{
  if (((Interval >= MIX_LOCKED_IN_HINT_INTERVAL_TIME) && (Interval <= MAX_LOCKED_IN_HINT_INTERVAL_TIME)) || (Interval == 0))
  {
    DeviceInformation.DeviceAttribute.LockedInBlinkingInterval = Interval;
    return true;
  }

  return false;
}

bool GetDnsServerAddress(void *pMaskAddr)
{
  if (pMaskAddr != NULL)
  {
    memcpy(pMaskAddr, DeviceInformation.NetworkAttribute.DnsAddress, NUMBER_OF_SERVER_IP_ADDRESS);
    return true;
  }

  return false;
}

bool SetDnsServerAddress(const void *pIpAddrIn)
{
  if (pIpAddrIn != NULL)
  {
    memcpy(DeviceInformation.NetworkAttribute.DnsAddress, pIpAddrIn, NUMBER_OF_SERVER_IP_ADDRESS);
    return true;
  }

  return false;
}

bool GetMqttPublishTopic(void *pTopic)
{
  if (pTopic != NULL)
  {
    memcpy(pTopic, DeviceInformation.NetworkAttribute.Publish, NUMBER_OF_MQTT_TOPIC_BIT);
    return true;
  }

  return false;
}

bool SetMqttPublishTopic(const void *pTopic)
{
  if ((pTopic != NULL))
  {
    const char *pPublishTopic = (const char *)pTopic;
    if (strlen(pPublishTopic) <= NUMBER_OF_MQTT_TOPIC_BIT)
    {
      memset(DeviceInformation.NetworkAttribute.Publish, 0, NUMBER_OF_MQTT_TOPIC_BIT);
      strcpy(DeviceInformation.NetworkAttribute.Publish, pPublishTopic);

      return true;
    }
  }

  return false;
}

bool GetMqttSubscribeTopic(void *pTopic)
{
  if (pTopic != NULL)
  {
    memcpy(pTopic, DeviceInformation.NetworkAttribute.Subscribe, NUMBER_OF_MQTT_TOPIC_BIT);
    return true;
  }

  return false;
}

bool SetMqttSubscribeTopic(const void *pTopic)
{
  if (pTopic != NULL)
  {
    const char *pSubscribeTopic = (const char *)pTopic;
    if (strlen(pSubscribeTopic) <= NUMBER_OF_MQTT_TOPIC_BIT)
    {
      memset(DeviceInformation.NetworkAttribute.Subscribe, 0, NUMBER_OF_MQTT_TOPIC_BIT);
      strcpy(DeviceInformation.NetworkAttribute.Subscribe, pSubscribeTopic);

      return true;
    }
  }

  return false;
}

bool GetMqttPassword(void *pPassword)
{
  if (pPassword != NULL)
  {
    memcpy(pPassword, DeviceInformation.NetworkAttribute.Password, NUMBER_OF_MQTT_PASSWORD_BIT);
    return false;
  }

  return true;
}

bool SetMqttPassword(const void *pPassword)
{
  if (pPassword != NULL)
  {
    const char *pMqttPassword = (const char *)pPassword;

    if (strlen(pMqttPassword) <= NUMBER_OF_MQTT_PASSWORD_BIT)
    {
      memset(DeviceInformation.NetworkAttribute.Password, 0, NUMBER_OF_MQTT_PASSWORD_BIT);
      strcpy(DeviceInformation.NetworkAttribute.Password, pMqttPassword);

      return true;
    }
  }

  return false;
}

uint16_t GetNetworkServerPort(void)
{
  return DeviceInformation.NetworkAttribute.ServerPort;
}

bool SetNetworkServerPort(uint16_t ServerPort)
{
  DeviceInformation.NetworkAttribute.ServerPort = ServerPort;
  return true;
}

bool GetNetworkDomianName(void *pMaskAddr)
{
  if (pMaskAddr != NULL)
  {
    memcpy(pMaskAddr, DeviceInformation.NetworkAttribute.DomianName, NUMBER_OF_SERVER_DOMIAN_NAME_BIT);
    return true;
  }

  return false;
}

bool SetNetworkDomianName(const void *pDomianName)
{
  if (pDomianName != NULL)
  {
    const char *pMqttDomianName = (const char *)pDomianName;

    if (strlen(pMqttDomianName) <= NUMBER_OF_SERVER_DOMIAN_NAME_BIT)
    {
      memset(DeviceInformation.NetworkAttribute.DomianName, 0, NUMBER_OF_SERVER_DOMIAN_NAME_BIT);
      strcpy(DeviceInformation.NetworkAttribute.DomianName, pMqttDomianName);

      return true;
    }
  }

  return false;
}

bool GetServerConnectAddress(void *pIpAddrOut)
{
  if (pIpAddrOut != NULL)
  {
    memcpy(pIpAddrOut, DeviceInformation.NetworkAttribute.ServerAddress, NUMBER_OF_SERVER_IP_ADDRESS);
    return true;
  }

  return false;
}

bool SetServerConnectAddress(const void *pIpAddrIn)
{
  if (pIpAddrIn != NULL)
  {
    memcpy(DeviceInformation.NetworkAttribute.ServerAddress, pIpAddrIn, NUMBER_OF_SERVER_IP_ADDRESS);

    return true;
  }

  return false;
}

bool GetMqttUserName(void *pUserName)
{
  if (pUserName != NULL)
  {
    memcpy(pUserName, DeviceInformation.NetworkAttribute.UserName, NUMBER_OF_MQTT_USER_NAME_BIT);
    return false;
  }

  return false;
}

bool SetMqttUserName(const void *pUserName)
{
  if (pUserName != NULL)
  {
    const char *pMqttUserName = (const char *)pUserName;

    if (strlen(pMqttUserName) <= NUMBER_OF_MQTT_USER_NAME_BIT)
    {
      memset(DeviceInformation.NetworkAttribute.UserName, 0, NUMBER_OF_MQTT_USER_NAME_BIT);
      strcpy(DeviceInformation.NetworkAttribute.UserName, pMqttUserName);

      return true;
    }
  }

  return false;
}

uint8_t GetWirelessModuleEmissionPower(void)
{
  uint8_t EmissionPower = DeviceInformation.NetworkAttribute.WirelessModuleEmissionPower;

  if (((EmissionPower >= MIX_WIRELESS_MODULE_EMISSION_POWER) && (EmissionPower <= MAX_WIRELESS_MODULE_EMISSION_POWER)) || (EmissionPower == 0))
    return EmissionPower;

  return DEFAULT_WIRELESS_MODULE_EMISSION_POWER;
}

bool SetWirelessModuleEmissionPower(uint8_t EmissionPower)
{
  if (((EmissionPower >= MIX_WIRELESS_MODULE_EMISSION_POWER) && (EmissionPower <= MAX_WIRELESS_MODULE_EMISSION_POWER)) || (EmissionPower == 0))
  {
    DeviceInformation.NetworkAttribute.WirelessModuleEmissionPower = EmissionPower;
    return true;
  }

  return false;
}

uint8_t GetWirelessModuleSearchNetworkTimeout(void)
{
  uint8_t NetworkTimeout = DeviceInformation.NetworkAttribute.WirelessModuleNetworkTimeout;

  if ((NetworkTimeout >= MIX_WIRELESS_MODULE_NETWORK_TIMEOUT) && (NetworkTimeout <= MAX_WIRELESS_MODULE_NETWORK_TIMEOUT))
    return NetworkTimeout;

  return DEFAULT_WIRELESS_MODULE_NETWORK_TIMEOUT;
}

bool SetWirelessModuleNetworkTimeout(uint8_t NetworkTimeout)
{
  DeviceInformation.NetworkAttribute.WirelessModuleNetworkTimeout = NetworkTimeout;
  return true;
}

uint8_t GetWirelessModuleFrequencyRange(void)
{
  uint8_t FrequencyRange = DeviceInformation.NetworkAttribute.WirelessModuleFrequencyRange;

  if (((FrequencyRange >= MIX_WIRELESS_MODULE_FREQUENCY_RANGE) && (FrequencyRange <= MAX_WIRELESS_MODULE_FREQUENCY_RANGE)) || (FrequencyRange == 0))
    return FrequencyRange;

  return DEFAULT_WIRELESS_MODULE_FREQUENCY_RANGE;
}

bool SetWirelessModuleFrequencyRange(uint8_t FrequencyRange)
{
  if (((FrequencyRange >= MIX_WIRELESS_MODULE_FREQUENCY_RANGE) && (FrequencyRange <= MAX_WIRELESS_MODULE_FREQUENCY_RANGE)) || (FrequencyRange == 0))
  {
    DeviceInformation.NetworkAttribute.WirelessModuleFrequencyRange = FrequencyRange;
    return true;
  }

  return false;
}

uint8_t GetLockGardenIdNumber(void)
{
  return DeviceInformation.LicenceInformation.AffiliationAttribute.GardenId;
}

bool SetLockGardenIdNumber(uint8_t GardenId)
{
  DeviceInformation.LicenceInformation.AffiliationAttribute.GardenId = GardenId;
  return true;
}

uint8_t GetLockBuildingNumber(void)
{
  return DeviceInformation.LicenceInformation.AffiliationAttribute.BuildingId;
}

bool SetLockBuildingNumber(uint8_t BuildingId)
{
  DeviceInformation.LicenceInformation.AffiliationAttribute.BuildingId = BuildingId;
  return true;
}

uint8_t GetLockFloorNumber(void)
{
  return DeviceInformation.LicenceInformation.AffiliationAttribute.FloorId;
}

bool SetLockFloorNumber(uint8_t FloorId)
{
  DeviceInformation.LicenceInformation.AffiliationAttribute.FloorId = FloorId;
  return true;
}

uint32_t GetLockRoomIdNumber(void)
{
  return DeviceInformation.LicenceInformation.AffiliationAttribute.RoomId;
}

bool SetLockRoomIdNumber(uint32_t RoomId)
{
  DeviceInformation.LicenceInformation.AffiliationAttribute.RoomId = RoomId;
  return true;
}

uint8_t GetLockSubroomNumber(void)
{
  return DeviceInformation.LicenceInformation.AffiliationAttribute.SubroomId;
}

bool SetLockSubroomNumber(uint8_t SubroomId)
{
  DeviceInformation.LicenceInformation.AffiliationAttribute.SubroomId = SubroomId;
  return true;
}

uint16_t GetRoomType(void)
{
  return DeviceInformation.LicenceInformation.AffiliationAttribute.RoomType;
}

bool SetRoomType(uint16_t RoomType)
{
  DeviceInformation.LicenceInformation.AffiliationAttribute.RoomType = RoomType;
  return true;
}

uint32_t GetGroupingNumber(void)
{
  return DeviceInformation.LicenceInformation.AffiliationAttribute.GroupingNumber;
}

bool SetGroupingNumber(uint32_t GroupingNumber)
{
  DeviceInformation.LicenceInformation.AffiliationAttribute.GroupingNumber = GroupingNumber;
  return true;
}

uint8_t GetCardOperationSector(void)
{
#if 1 //测试10扇区时可关闭
  uint8_t SectorNumber = DeviceInformation.LicenceInformation.CardAccessAttribute.Sector;

  if ((SectorNumber >= START_OPERATION_M1_SECTOR) && (SectorNumber <= END_OPERATION_M1_SECTOR))
    return SectorNumber;
#endif

  return DEFAULT_OPERATION_M1_SECTOR;
}

bool SetCardOperationSector(uint8_t SectorNumber)
{
  if ((SectorNumber >= START_OPERATION_M1_SECTOR) && (SectorNumber <= END_OPERATION_M1_SECTOR))
  {
    DeviceInformation.LicenceInformation.CardAccessAttribute.Sector = SectorNumber;
    return true;
  }

  return false;
}

uint8_t GetThirdPartyTypeOfReading(void)
{
  return DeviceInformation.LicenceInformation.CardAccessAttribute.ThirdPartyTypeOfReading;
}

bool SetThirdPartyTypeOfReading(uint8_t ThirdPartyTypeOfReading)
{
  DeviceInformation.LicenceInformation.CardAccessAttribute.ThirdPartyTypeOfReading = ThirdPartyTypeOfReading;
  return true;
}


uint8_t GetReadTheCardType(void)
{
  uint8_t ReadType = DeviceInformation.LicenceInformation.CardAccessAttribute.TypeOfReading;

  switch (ReadType)
  {
  case READER_BY_CPU_CARD:
  case READER_BY_MIFARE_CARD:
  case READER_BY_IDENTIY_CARD:
  case READER_BY_MIFARE_CPU_CRAD:
  case READER_BY_CPU_IDENTIY_CARD:
  case READER_BY_MIFARE_IDENTIY_CRAD:
  case READER_BY_H_WORLD_GROUP_CPU_CARD:
  case READER_BY_H_WORLD_GROUP_MIFARE_CARD:
    return ReadType;
  }

  return READER_BY_MIFARE_CARD;
}

bool SetReadTheCardType(uint8_t ReadType)
{
  bool OperationStatus = false;

  switch (ReadType)
  {
  case READER_BY_CPU_CARD:
  case READER_BY_MIFARE_CARD:
  case READER_BY_IDENTIY_CARD:
  case READER_BY_MIFARE_CPU_CRAD:
  case READER_BY_CPU_IDENTIY_CARD:
  case READER_BY_MIFARE_IDENTIY_CRAD:
  case READER_BY_H_WORLD_GROUP_CPU_CARD:
  case READER_BY_H_WORLD_GROUP_MIFARE_CARD:
  {
    OperationStatus = true;
    DeviceInformation.LicenceInformation.CardAccessAttribute.TypeOfReading = ReadType;
  }
  break;
  }

  return OperationStatus;
}

bool GetCardOperationSectorKey(uint8_t *pKey)
{
  PRINT("[device_parameter] : GetCardOperationSectorKey[\r\n");
  for (uint8_t i=0;i<CRAD_SECTOR_KEY_LENGTH;i++)
  {
    PRINT("%02x ", DeviceInformation.LicenceInformation.CardAccessAttribute.SectorKey[i]);
  }
  PRINT("]\r\n");

  if (pKey != NULL)
  {
    memcpy(pKey, DeviceInformation.LicenceInformation.CardAccessAttribute.SectorKey, CRAD_SECTOR_KEY_LENGTH);
    return true;
  }

  return false;
}

bool SetCardOperationSectorKey(const uint8_t *pKeyIn)
{
  PRINT("[device_parameter] : SetCardOperationSectorKey[\r\n");
  for (uint8_t i=0;i<CRAD_SECTOR_KEY_LENGTH;i++)
  {
    PRINT("%02x ", pKeyIn[i]);
  }
  PRINT("]\r\n");
  if (pKeyIn != NULL)
  {
    memcpy(DeviceInformation.LicenceInformation.CardAccessAttribute.SectorKey, pKeyIn, CRAD_SECTOR_KEY_LENGTH);
    return true;
  }

  return false;
}

bool GetElevatorCardOperationSectorKey(uint8_t *pKey)
{
  PRINT("[device_parameter] : GetElevatorCardOperationSectorKey[\r\n");
  for (uint8_t i=0;i<CRAD_SECTOR_KEY_LENGTH;i++)
  {
    PRINT("%02x ", DeviceInformation.LicenceInformation.ElevatorCardAccessAttribute.SectorKey[i]);
  }
  PRINT("]\r\n");

  if (pKey != NULL)
  {
    memcpy(pKey, DeviceInformation.LicenceInformation.ElevatorCardAccessAttribute.SectorKey, CRAD_SECTOR_KEY_LENGTH);
    return true;
  }

  return false;
}

bool SetElevatorCardOperationSectorKey(const uint8_t *pKeyIn)
{
  PRINT("[device_parameter] : SetElevatorCardOperationSectorKey[\r\n");
  for (uint8_t i=0;i<CRAD_SECTOR_KEY_LENGTH;i++)
  {
    PRINT("%02x ", pKeyIn[i]);
  }
  PRINT("]\r\n");
  if (pKeyIn != NULL)
  {
    memcpy(DeviceInformation.LicenceInformation.ElevatorCardAccessAttribute.SectorKey, pKeyIn, CRAD_SECTOR_KEY_LENGTH);
    return true;
  }

  return false;
}

uint8_t GetElevatorCardOperationSector(void)
{
  
  uint8_t SectorNumber = DeviceInformation.LicenceInformation.ElevatorCardAccessAttribute.Sector;
  PRINT("[device_parameter] : GetElevatorCardOperationSector SectorNumber = %d\r\n", SectorNumber);

  if ((SectorNumber >= START_OPERATION_M1_SECTOR) && (SectorNumber <= END_OPERATION_M1_SECTOR))
    return SectorNumber;

  return DEFAULT_OPERATION_M1_SECTOR;
}

bool SetElevatorCardOperationSector(uint8_t SectorNumber)
{
  PRINT("[device_parameter] : SetElevatorCardOperationSector %d\r\n", SectorNumber);
  if ((SectorNumber >= START_OPERATION_M1_SECTOR) && (SectorNumber <= END_OPERATION_M1_SECTOR))
  {
    DeviceInformation.LicenceInformation.ElevatorCardAccessAttribute.Sector = SectorNumber;
    return true;
  }

  return false;
}

uint8_t GetEleControlBoardNumber(void)
{
  return DeviceInformation.DeviceAttribute.EleControlBoardNumber;
}

bool SetEleControlBoardNumber(uint8_t Number)
{
  DeviceInformation.DeviceAttribute.EleControlBoardNumber = Number;
}

uint32_t GetCustomerCode(void)
{
  return DeviceInformation.LicenceInformation.SystemAccessAttribute.CustomerCode;
}

bool SetCustomerCode(uint32_t CustomerCode)
{
  DeviceInformation.LicenceInformation.SystemAccessAttribute.CustomerCode = CustomerCode;
  return true;
}

uint32_t GetAuthorizationEndTime(void)
{
  return DeviceInformation.LicenceInformation.SystemAccessAttribute.AuthorizationEndTime;
}

bool SetAuthorizationEndTime(uint32_t EndTime)
{
  DeviceInformation.LicenceInformation.SystemAccessAttribute.AuthorizationEndTime = EndTime;
  return true;
}

bool GetEncryptionKey(void *pEncryptionKey)
{
  if (pEncryptionKey != NULL)
  {
    memcpy(pEncryptionKey, DeviceInformation.LicenceInformation.SystemAccessAttribute.EncryptionKey, ENCRYPTION_KEY_LENGTH);
    return true;
  }

  return false;
}

bool SetEncryptionKey(const void *pEncryptionKey)
{
  if (pEncryptionKey != NULL)
  {
    uint8_t EncryptionKey[ENCRYPTION_KEY_LENGTH] = {0};

    memset(EncryptionKey, 0, ENCRYPTION_KEY_LENGTH);
    if (memcmp(EncryptionKey, pEncryptionKey, ENCRYPTION_KEY_LENGTH) != 0)
    {
      memcpy(DeviceInformation.LicenceInformation.SystemAccessAttribute.EncryptionKey, pEncryptionKey, ENCRYPTION_KEY_LENGTH);
      return true;
    }
  }

  return false;
}

bool GetSuperAdministratorPassword(void *pPassword)
{
  if (pPassword != NULL)
  {
    memcpy(pPassword, DeviceInformation.LicenceInformation.SystemAccessAttribute.SuperAdminPassword, NUMBER_OF_KEYBOARD_KEY);
    return true;
  }

  return false;
}

bool SetSuperAdministratorPassword(const void *pPassword)
{
  if (pPassword != NULL)
  {
    const char *pSuperAdminPassword = (const char *)pPassword;

    for (uint8_t i = 0; i < NUMBER_OF_KEYBOARD_KEY; i++)
    {
      if ((pSuperAdminPassword[i] < '0') || (pSuperAdminPassword[i] > '9'))
        return false;
    }

    memcpy(DeviceInformation.LicenceInformation.SystemAccessAttribute.SuperAdminPassword, pSuperAdminPassword, NUMBER_OF_KEYBOARD_KEY);
    return true;
  }

  return false;
}

bool GetDayBroadcastContorlEn(void)
{
  if (DeviceInformation.LicenceInformation.RemainingDaysAttribute.ContorlEn)
    return true;

  return false;
}

bool SetDayBroadcastContorlEn(uint8_t ContorlEn)
{
  if ((ContorlEn == true) || (ContorlEn == false))
  {
    DeviceInformation.LicenceInformation.RemainingDaysAttribute.ContorlEn = ContorlEn;
    return true;
  }

  return false;
}

uint8_t GetBroadcastRemainingDays(void)
{
  uint8_t Days = DeviceInformation.LicenceInformation.RemainingDaysAttribute.RemainingDays;

  if ((Days >= MIX_BROADCAST_DAYS) && (Days <= MAX_BROADCAST_DAYS))
    return Days;

  return DEFAULT_BROADCAST_DAYS;
}

bool SetBroadcastRemainingDays(uint8_t Days)
{
  if ((Days >= MIX_BROADCAST_DAYS) && (Days <= MAX_BROADCAST_DAYS))
  {
    DeviceInformation.LicenceInformation.RemainingDaysAttribute.RemainingDays = Days;
    return true;
  }

  return false;
}

uint8_t GetNoDisturbingStartHour(void)
{
  if ((DeviceInformation.NoDisturbingSetting.StartHour >= 0) && (DeviceInformation.NoDisturbingSetting.StartHour <= 24))
    return DeviceInformation.NoDisturbingSetting.StartHour;

  return 0;
}

bool SetNoDisturbingStartHour(uint8_t StartHour)
{
  if ((StartHour >= 0) && (StartHour <= 24))
  {
    DeviceInformation.NoDisturbingSetting.StartHour = StartHour;
    return true;
  }

  return false;
}

uint8_t GetNoDisturbingStartMinute(void)
{
  if ((DeviceInformation.NoDisturbingSetting.StartMinute >= 0) && (DeviceInformation.NoDisturbingSetting.StartMinute <= 60))
    return DeviceInformation.NoDisturbingSetting.StartMinute;

  return 0;
}

bool SetNoDisturbingStartMinute(uint8_t StartMinute)
{
  if ((StartMinute >= 0) && (StartMinute <= 60))
  {
    DeviceInformation.NoDisturbingSetting.StartMinute = StartMinute;
    return true;
  }

  return false;
}

uint8_t GetNoDisturbingEndHour(void)
{
  if ((DeviceInformation.NoDisturbingSetting.EndHour >= 0) && (DeviceInformation.NoDisturbingSetting.EndHour <= 24))
    return DeviceInformation.NoDisturbingSetting.EndHour;

  return 0;
}

bool SetNoDisturbingEndHour(uint8_t EndHour)
{
  if ((EndHour >= 0) && (EndHour <= 24))
  {
    DeviceInformation.NoDisturbingSetting.EndHour = EndHour;
    return true;
  }

  return false;
}

uint8_t GetNoDisturbingEndMinute(void)
{
  if ((DeviceInformation.NoDisturbingSetting.EndMinute >= 0) && (DeviceInformation.NoDisturbingSetting.EndMinute <= 60))
    return DeviceInformation.NoDisturbingSetting.EndMinute;

  return 0;
}

bool SetNoDisturbingEndMinute(uint8_t EndMinute)
{
  if ((EndMinute >= 0) && (EndMinute <= 60))
  {
    DeviceInformation.NoDisturbingSetting.EndMinute = EndMinute;
    return true;
  }

  return false;
}

uint8_t GetElevatorId(void)
{
  return DeviceInformation.DeviceAttribute.ElevatorId;
}

bool SetElevatorId(uint8_t Id)
{
  DeviceInformation.DeviceAttribute.ElevatorId = Id;
  return true;
}

uint8_t GetElevatorStartFloor(void)
{
  PRINT("[device parameter] : 1 GetElevatorStartFloor = %d\r\n", DeviceInformation.DeviceAttribute.ElevatorStartFloor);
  return DeviceInformation.DeviceAttribute.ElevatorStartFloor;
}

bool SetElevatorStartFloor(uint8_t ElevatorStartFloor)
{
  DeviceInformation.DeviceAttribute.ElevatorStartFloor = ElevatorStartFloor;
  return true;
}

bool SetPublicFloorData(uint8_t *Data)
{
  if ((Data != NULL))
  {
    memcpy(DeviceInformation.DeviceAttribute.ElevatorPublicFloorData, Data, FLOOR_ARRAY_DATA_LEN);
    return true;
  }
  return false;
}

bool GetPublicFloorData(uint8_t *Data)
{
  if (Data != NULL)
  {
    memcpy(Data, DeviceInformation.DeviceAttribute.ElevatorPublicFloorData, FLOOR_ARRAY_DATA_LEN);
    return true;
  }
  return false;
}


bool GetIoBoardFirmwareVersionNumber(char *pVersion)
{
  if (pVersion != NULL)
  {
    memcpy(pVersion, DeviceInformation.VersionControl.IoBoardFirmwareVersionNumber, NUMBER_OF_FIRMWARE_VERSION);
    return true;
  }
  return false;
}
bool SetIoBoardFirmwareVersionNumber(char *pVersion)
{
  if (pVersion != NULL)
  {
    const char *pFirmwareVersionNumber = (const char *)pVersion;
    if (strlen(pFirmwareVersionNumber) <= NUMBER_OF_FIRMWARE_VERSION)
    {
      memset(DeviceInformation.VersionControl.IoBoardFirmwareVersionNumber, 0, NUMBER_OF_FIRMWARE_VERSION);
      strcpy(DeviceInformation.VersionControl.IoBoardFirmwareVersionNumber, pFirmwareVersionNumber);
      return true;
    }
  }
  return false;
}

// 设置io板中，某一个主板序号的固件版本号
bool SetIoBoardFirmwareVersionByTable(uint8_t IoboardAddress, char *FirmwareVersion)
{
  if (((IoboardAddress - 1) < IOBOARD_DEVICE_NUM) && (FirmwareVersion != NULL)) // 下标比8小，且指针有效
  {
    memcpy(IoboardDeviceInfoTable[IoboardAddress - 1].FirmwareVersion, FirmwareVersion, NUMBER_OF_FIRMWARE_VERSION);
    return true;
  }
  return false;
}

// 获取io板表中，某一个主板序号的固件版本号
bool GetIoBoardFirmwareVersionByTable(uint8_t IoboardAddress, char *FirmwareVersion)
{
  if (((IoboardAddress - 1) < IOBOARD_DEVICE_NUM) && (FirmwareVersion != NULL)) // 下标比8小，且指针有效
  {
    memcpy(FirmwareVersion, IoboardDeviceInfoTable[IoboardAddress - 1].FirmwareVersion, NUMBER_OF_FIRMWARE_VERSION);
    return true;
  }
  return false;
}

// static uint8_t SupportIoboardNumber = 0; // 支持的io板数量

// uint8_t GetSupportIoBoardNumber(void)
// {
//   return SupportIoboardNumber;
// }

// bool SetSupportIoBoardNumber(uint8_t Number)
// {
//   if (Number <= IOBOARD_DEVICE_NUM)
//   {
//     SupportIoboardNumber = Number;
//     return true;
//   }
//   return false;
// }

static IoBoardFirmwareInfo_t s_IoBoardFirmwareInfo = {0};

IoBoardFirmwareInfo_t *GetBoardFirmwareInfoPtr(void)
{
  return &s_IoBoardFirmwareInfo;
}

uint8_t GetIoBoardFirmwareExistFlag(void)
{
  return DeviceInformation.DeviceAttribute.BoardFirmwareExistFlag;
}

bool SetIoBoardFirmwareExistFlag(uint8_t Flag)
{
  DeviceInformation.DeviceAttribute.BoardFirmwareExistFlag = Flag;
  return true;
}

uint8_t GetEleControlSwitch(void)
{
  return DeviceInformation.DeviceAttribute.EleControlSwitch;
}

bool SetEleControlSwitch(uint8_t Switch)
{
  DeviceInformation.DeviceAttribute.EleControlSwitch = Switch;
  return true;
}

uint8_t GetFireAlarmMode(void)
{
  return DeviceInformation.DeviceAttribute.FireAlarmMode;
}

bool SetFireAlarmMode(uint8_t Mode)
{
  DeviceInformation.DeviceAttribute.FireAlarmMode = Mode;
  return true;
}

bool SetBleMasterConnectRssi(uint8_t Rssi)
{
  DeviceInformation.DeviceAttribute.BleMasterConnectRssi = Rssi;
  return true;
}

uint8_t GetBleMasterConnectRssi(void)
{
  return DeviceInformation.DeviceAttribute.BleMasterConnectRssi;
}

bool SetMasterModeSwitch(uint8_t Switch)
{
  DeviceInformation.DeviceAttribute.MasterModeSwitch = Switch;
  return true;
}

uint8_t GetMasterModeSwitch(void)
{
  return DeviceInformation.DeviceAttribute.MasterModeSwitch;
}

static uint8_t CurrentUpdateBoardId = 0;
static uint8_t CurrentUpdateBoardStatus = 0;
uint8_t GetCurrentUpdateBoardId(void)
{
  return CurrentUpdateBoardId;
}

uint8_t GetCurrentUpdateBoardStatus(void)
{
    return CurrentUpdateBoardStatus;
}

bool SetCurrentUpdateBoardId(uint8_t Id)
{
  CurrentUpdateBoardId = Id;
  return true;
}

bool SetCurrentUpdateBoardStatus(uint8_t Status)
{
  CurrentUpdateBoardStatus = Status;
  return true;
}

//tag: 恢复默认用户参数
void RestoreDefaultUserParameters(void)
{
  {
    SetOfflineCardFunctionEnable(0);
    SetUnlockTime(DEFAULT_UNLOCKING_TIME);
    SetSystemVolumeLevel(DEFAULT_VOLUME_LEVEL);
    SetSystemTimeZone(DEFAULT_TIME_ZONE_OFFSET);
    SetHeartbeatTransmissionCycle(DEFAULT_HEARTBEAT_CYCLE);
    SetBluetoothConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
    SetBluetoothUpdateRaidioInterval(DEFAULT_UPDATE_BLUETOOTH_BROADCAST_INTERVAL);
  }

  {
    SetRoomType(0);
    SetGroupingNumber(0);
    SetLockFloorNumber(0);
    SetLockRoomIdNumber(0);
    SetLockSubroomNumber(0);
    SetLockGardenIdNumber(0);
    SetLockBuildingNumber(0);
  }

  {
    SetParkCardReplaceTime(0);
    SetGuestCardReplaceTime(0);
    SetBuildCardReplaceTime(0);
    SetFloorCardReplaceTime(0);
    SetMasterCardReplaceTime(0);
    SetNormalOpenCardReplaceTime(0);

    SetParkCardReplaceId(0);
    SetGuestCardReplaceId(0);
    SetBuildCardReplaceId(0);
    SetFloorCardReplaceId(0);
    SetMasterCardReplaceId(0);
    SetNormalOpenCardReplaceId(0);
  }
  {
    SetDayBroadcastContorlEn(false);
    SetBroadcastRemainingDays(DEFAULT_BROADCAST_DAYS);
  }

  {
    SetAuthorizationEndTime(0);
    SetDeviceInitStatus(FACTORY_SETTING);
    SetEncryptionKey(DEFAULT_ENCRYPTION_KEY_VALUE);
    SetCardOperationSectorKey(DEFAULT_M1_ACCESS_KEY);
    SetCardOperationSector(DEFAULT_OPERATION_M1_SECTOR);
    SetSuperAdministratorPassword(DEFAULT_SUPER_ADMIN_PASSWORD);
  }

  {
    SetNoDisturbingEndHour(0);
    SetNoDisturbingEndMinute(0);
    SetNoDisturbingStartHour(0);
    SetNoDisturbingStartMinute(0);
  }

  {
    SetElevatorStartFloor(1);//初始化设置起始楼层
    SetElevatorId(1);//初始化设置机号
    SetElevatorCardOperationSector(10);//初始化默认梯控扇区
    SetThirdPartyTypeOfReading(THIRD_PARTY_READ_TYPE_DOOR_LOCK_SPEI);//初始化默认三方识读模式
    SetElevatorCardOperationSectorKey(DEFAULT_M1_ACCESS_KEY);//梯控扇区密钥
    SetEleControlBoardNumber(0);
    SetEleControlSwitch(0x10);//停用
    SetFireAlarmMode(0x10);
    SetBleMasterConnectRssi(60);
    SetMasterModeSwitch(0x10);//关闭
  }
}

void InitialisingDeviceParameters(void)
{
  memset(&DeviceInformation, 0, sizeof(DeviceInformation_t));

  SetNormalOpenEn(false);
  SetTheKeyToResetEn(false);
  SetStartTimeVerifyEn(false);
  SetAllowedToOpenDoubleLockEn(false);

  SetRfidErrorPromptFunctionEn(false);
  SetSafetyModuleErrorPromptFunctionEn(true);
  SetSystemLockedTime(DEFAULT_SYSTEM_LOCKED_TIME);

#if ((_BOARD_TYPE_ & _V33_BOARD_) == _V33_BOARD_)
#if _NETWOK_MODLE_TYPE_ == _ML307R_MODLE_
  SetObtainTheDeviceModel(B4_CMA);
#elif _NETWOK_MODLE_TYPE_ == _TP1107_MODULE_
  SetObtainTheDeviceModel(BT_CMA);
#endif

#elif ((_BOARD_TYPE_ & _V31_BOARD_) == _V31_BOARD_)
#if _NETWOK_FUNCTION_ENABLE_

#if _NETWOK_MODLE_TYPE_ == _ML307R_MODLE_
  SetObtainTheDeviceModel(B4_CMA);
#else
  SetObtainTheDeviceModel(BT_C);
#endif

#else
  SetObtainTheDeviceModel(B_C);
#endif

#elif ((_BOARD_TYPE_ & _V32_BOARD_) == _V32_BOARD_)
  SetObtainTheDeviceModel(B_C);

#elif ((_BOARD_TYPE_ & _DA01_BOARD_) == _DA01_BOARD_)
  SetObtainTheDeviceModel(MJ_BCMQ_01);
#elif ((_BOARD_TYPE_ & _CR01_BU_) == _CR01_BU_)
  SetObtainTheDeviceModel(CR01_BU);
#endif

  SetNetworkOperator(CHINA_MOBILE);
  SetMqttPassword(DEFAULT_MATT_PASSWORD);
  SetMqttUserName(DEFAULT_MQTT_USER_NAME);
  SetNetworkDomianName(DEFAULT_DOMAIN_NAME);
  SetWirelessModuleEmissionPower(DEFAULT_WIRELESS_MODULE_EMISSION_POWER);
  SetWirelessModuleFrequencyRange(DEFAULT_WIRELESS_MODULE_FREQUENCY_RANGE);
  SetWirelessModuleNetworkTimeout(DEFAULT_WIRELESS_MODULE_NETWORK_TIMEOUT);

  SetServerConnectAddress(DEFAULT_SERVER_ADDRESS);
  SetDnsServerAddress(DEFAULT_DNS_SERVER_ADDRESS);
  SetMqttPublishTopic(DEFAULT_MQTT_PUBLISH_TOPIC);
  SetNetworkServerPort(DEFAULT_CONNECT_SERVER_PORT);
  SetMqttSubscribeTopic(DEFAULT_MQTT_SUBSCRIBE_TOPIC);

  SetProtocolFormat(PROTOCOL_FORMAT_YGS);
  SetThirdPartyTypeOfReading(THIRD_PARTY_READ_TYPE_DOOR_LOCK_SPEI);//初始化默认三方识读模式
  SetElevatorCardOperationSector(10);//初始化默认梯控扇区
  SetElevatorStartFloor(1);//初始化设置起始楼层
  SetElevatorId(1);//初始化设置机号
  SetElevatorCardOperationSectorKey(DEFAULT_M1_ACCESS_KEY);//梯控扇区密钥
  SetEleControlBoardNumber(0);
  SetEleControlSwitch(0x10);//停用
  SetFireAlarmMode(0x10);//停用
  SetBleMasterConnectRssi(60);
  SetMasterModeSwitch(0x10);//关闭
  SetSearchTimeout(DEFAULT_FACE_SEARCH_TIME);
  SetMotorDriveTime(DEFAULT_MOTOR_DRIVE_TIME);
  WriteCircuitBoardType(DEFAULT_PCB_BOARD_TYPE);
  SettingTheChipModel(DEFAULT_CHIP_MODEL_NUMBER);
  SetDeviceFirmwareVersion(DEFAULT_FIRMWARE_VERSION);
  SetNumberOfCardholder(DEFAULT_NUMBER_OF_CARDHOLDER);
  SetAllowableTimeError(DEFAULT_ALLOWABLE_TIME_ERROR);
  SetKeyboardSensitivity(DEFAULT_KEYBOARD_SENSITIVITY);
  SetQualityInspectorCode(DEFAULT_QUALITY_INSPECTOR_CODE);
  SetDeviceLastActionTime(DEFAULT_AUTHORIZATION_START_TIME);
  SetTheDeviceDeliveryDate(DEFAULT_AUTHORIZATION_START_TIME);
  SetCardReadingSensitivity(DEFAULT_CARD_RECOGNITION_SENSITIVITY);
  SetLockedInReminderInterval(DEFAULT_LOCKED_IN_HINT_INTERVAL_TIME);
  SetNormalOpenReminderInterval(DEFAULT_NORMAL_OPEN_HINT_INTERVAL_TIME);
  SetBreakInDetcetionInterval(DEFAULT_BREAK_IN_DETCETION_INTERVAL_TIME);
  SetFalseLockDetcetionInterval(DEFAULT_FLASE_LOCK_DETCETION_INTERVAL_TIME);

  RestoreDefaultUserParameters();
}

void LoadDeviceParameterFromMemory(void)
{
  FlashReadDeviceParameterFile(0, &DeviceInformation, sizeof(DeviceInformation_t));
}

bool WriteDeviceParametersToMemory(void)
{
  return FlashWriteDeviceParameterFile(0, &DeviceInformation, sizeof(DeviceInformation_t));
}
static uint8_t DestinMacAddress[MAC_ADDR_CODING_LENGTH] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // Ŀ��MAC��ַ
bool ClearDestinMacAddress(void)
{
  memset(DestinMacAddress, 0, MAC_ADDR_CODING_LENGTH);
  return true;
}
bool SetDestinMacAddress(uint8_t *pMacAddress)
{
  if (pMacAddress != NULL)
  {
    memcpy(DestinMacAddress, pMacAddress, MAC_ADDR_CODING_LENGTH);
    return true;
  }
  return false;
}
bool GetDestinMacAddress(uint8_t *pMacAddress)
{
  if (pMacAddress != NULL)
  {
    memcpy(pMacAddress, DestinMacAddress, MAC_ADDR_CODING_LENGTH);
    return true;
  }
  return false;
}
